<?php

namespace Management\Controller;

use Think\Controller;

use Myself\FileSystem;

class MapController extends BaseController {


	//公众号的
	protected $appid = '';
	protected $appsecret = '';
	protected $m = NULL;
	protected $m_class = NULL;
	protected $m_config = NULL;
	protected $key = 'XBYBZ-MEPKU-RFLVA-BXEXT-BGGHH-A2BZ4';
	//.未付款 1. 未发货 2. 发货中 3. 已完成 4. 订单完成 5. 超时取消
    protected $statusArr=array(
        ['color'=>'dark','status'=>"未付款"],
        ['color'=>'default','status'=>"待分配"],
        ['color'=>'default','status'=>"已分配"],
        ['color'=>'blue','status'=>"司机到达"],
        ['color'=>'green','status'=>"待评价"],
        ['color'=>'dark','status'=>"评价完成"],
        ['color'=>'red','status'=>"已退款"],
        ['color'=>'default','status'=>"已取消"],
    );

    protected $statusdetail=array("尚未接单","分配订单","确认接单","到达出发地","装货完成","拍照完成","到达目的地","确认账单","确认二联单");


	public function _initialize(){
		parent::_initialize();
		$this->m = M('order');
		$info = M('wx_base')->where(['id'=>1])->find();
		$this->appid = $info['appid'];
		$this->appsecret = $info['appsecret'];
	}
	//关键词
	public function keyword(){
		$key = I('get.key');
		$url = 'https://apis.map.qq.com/ws/place/v1/suggestion/?region=沈阳&keyword='.$key.'&key='.$this->key;
		$res = json_decode(sendGet($url),true);
		if($res['status']==0){
			$data = $res['data'];
			$this->ajaxReturn(['status'=>1,'data'=>$data]);exit;
		}else{
			$this->ajaxReturn(['status'=>2,'msg'=>'请求失败']);exit;
		}
		
		// ll($data);die;
	}
	//路线规划
	public function line(){
		$data = I('post.');
		$url = "https://apis.map.qq.com/ws/direction/v1/driving/?from=".$data['start_lat'].','.$data['start_lng']."&to=".$data['end_lat'].','.$data['end_lng']."&&output=json&callback=cb&key=".$this->key;
		$res = json_decode(sendGet($url),true);
		if($res['status']==0){
			// ll($res['result']);
			$arr = $res['result']['routes'][0]['polyline'];
			$this->ajaxReturn(['status'=>1,'data'=>$arr,'mile'=>bcdiv($res['result']['routes'][0]['distance'],1000,2)]);exit;
		}else{
			$this->ajaxReturn(['status'=>2,'msg'=>'请求失败']);exit;
		}
	}
}